<template>
	<view>
		<view class="an-notice-box" :style="'background-color: '+bgColor+';'">
			<view class="an-notice-box-l">
				<view class="an-notice-icon">
					  <image class="uni-noticebar-icon" src="/static/icon/icon-shengyin.png" style="width: 40upx;height: 40upx;"></image>
				</view>
				<scroll-view class="an-notice-content">
					<swiper v-if="show" class="swiper" :autoplay="true" :interval="switchTime*1000" :duration="1500" :circular="true" :vertical="true">
						<swiper-item v-for="(item, index) in list" :key="index" :item-id="toString(index)" class="an-notice-content-item">
							<view class="swiper-item" @click="clickDet(item.id)">
								<text class="an-notice-content-item-text" :style="'color: '+color+';'">
									<!-- <text v-if="list.length > 1 || showSerial">{{index+1+'. '}}</text> -->
									{{item.title}}
								</text>
							</view>
						</swiper-item>
					</swiper>
				</scroll-view>
			</view>
			
			<view class="an-notice-more" @click="more" :style="{ color: moreColor }">
				<text>更多</text>
			</view>
		</view>
	</view>
</template>

<script>
	import uniIcons from '@/components/uni-icons/uni-icons.vue'
	export default {
		components: {
			uniIcons
		},
		props:{
			text: {
				type: String,
				default: '暂无未读消息'
			}, 
			color: {
				type: String,
				default: '#999999'
			},
			bgColor: {
				type: String,
				default: '#fff'
			},
			switchTime: {
				type: Number,
				default: 3
			},
			showSerial: {
				type: Boolean,
				default: true
			},
			moreColor:{
				type: String,
				default: '#198FFF'
			},
			list:{
				type:Array,
				default: () => {
					return ["啊实打实多阿达","阿达阿萨德阿萨德阿萨德","啊实打请问三分掐死实多阿达"]
				}
			}
		},
		data() {
			return {
				number: 0,
				//list: ['阿萨德饭','阿萨德'],
				copyText: '',
				show: true,
			};
		},
		mounted() {
			
			/* this.number = 0;
			this.startMove(); */
		},
		watch: {
			text: function () {
				this.show = true;
				if(this.text != this.copyText){
					this.copyText = this.text;
					this.list = this.text.split('|');
					console.log(JSON.stringify(this.list))
					if(this.list.length > 1){
						this.showSerial = true;
					}
				}
				/* this.number = 0;
				this.startMove(); */
			}
		},
		methods: {			
			/* startMove () {
			  // eslint-disable-next-line
			  let timer = setTimeout(() => {
				if (this.number === this.list.length-1) {
				  this.number = 0;
				} else {
				  this.number += 1;
				}
				this.startMove();
			  }, this.switchTime*1000);
			}, */
			more(){
				this.$emit('getmore')
			},
			clickDet(id) {
				this.$emit('getdet',id)
			},
		}
	}
</script>

<style lang="scss">
	.swiper{
		height: 60upx!important;
	}
	.an-notice-box{
		width: 100%; 
		height: 60upx; 
		display: flex; 
		align-items: center;
		justify-content: space-between;
		.an-notice-box-l{
			width: calc(100% - 80rpx);
			height: 60upx; 
			display: flex;
			align-items: center;
			overflow: hidden;
			margin: 20upx 0; 
		}
	}
	.an-notice-icon{
		text-align: center; 
		position: relative;
		margin-right: 10upx;
	}
	.an-notice-content{
		width: calc(100% - 80upx); 
		position: relative; 
		font-size: 14px;
	}
	.an-notice-content-item{
		width: 100%; 
		height: 60upx; 
		text-align: left; 
		line-height: 60upx;
	}
	.an-notice-content-item-text{
		display: block; 
		white-space: nowrap; 
		text-overflow: ellipsis; 
		overflow: hidden;
	}
	.an-notice-more{
		font-size: 18rpx;
		background: #E8F4FF;
		height: 32rpx;
		padding: 0 10rpx;
		border-radius: 4rpx;
	}
	
	@keyframes anotice {
		 0%  {transform: translateY(100%);}
	    30%  {transform: translateY(0);}
	    70%  {transform: translateY(0);}
	   100%  {transform: translateY(-100%);}
	}
</style>
